#include <stdio.h> /* UNIX */
#include <string.h> /* UNIX */
#include <atmi.h> /* TUXEDO */
#include <Uunix.h> /* TUXEDO */
#include <userlog.h> /* TUXEDO */
#define LINE 999999 /* size of reply line */
#if defined(__STDC__) || defined(__cplusplus)
main(int argc, char *argv[])
#else
main(argc, argv)
int argc;
char *argv[];
#endif
{
    int i; /*add variable在程序中加入的变量此程序中仅加入了这一个变量*/
    int cd; /* conversation descriptor */
    char *line; /* tux buffer holding reply */
    long len; /* length of recv'd line */
    long revent; /* events for send/recv */
    TPINIT *tpinitbuf ; /* for client identification */
    /*
    * Alloc a TPINIT buffer for identification purposes
    * This is not mandatory if no authentication is configured
    */
    tpinitbuf = (TPINIT *) tpalloc("TPINIT", NULL, TPINITNEED(16)) ;
    if (tpinitbuf == (TPINIT *) NULL)
    {
        (void)fprintf(stderr, "Failed for TPINIT buffer, %s\n",
                      tpstrerror(tperrno));
        (void)userlog("Failed for TPINIT buffer, %s",
                      tpstrerror(tperrno));
        exit(1);
    }
    /* Join application */
    if (tpinit(tpinitbuf) == -1)
    {
        (void)fprintf(stderr, "Failed to join application, %s\n",
                      tpstrerror(tperrno));
        (void)userlog("Failed to join application, %s",
                      tpstrerror(tperrno));
        exit(1);
    }

    /*
    * string buffer will be used to convey balance request and return
    * results from conversational service.
    */
    if ((line = tpalloc("XML","",LINE+1)) == (char *)NULL)
    {
        (void)fprintf(stderr,"tpalloc failed tperrno %d\n", tperrno);
        (void)userlog("tpalloc failed tperrno %d", tperrno);
        exit(1);
    }
    /* open connection to audit conversational service. */
 //   if ((cd = tpconnect("RtmasFncs",NULL,0,TPSENDONLY)) == -1)
 //   {
 //       (void)fprintf(stderr,"tpconnect failed tperrno %d\n", tperrno);
 //       (void)userlog("tpconnect failed tperrno %d", tperrno);
 //       (void)tpterm();
 //       exit(1);
 //   }
    /*下面这段程序中是循环向服务端发送0-9这9个数字的程序*/
  /*  for (i=0; i<10; i++)*/
    {
       /* (void)sprintf(line,"<HYATT xmlns='HYATT'><TUXEDO><SERVICENAME>RtmasFncs</SERVICENAME></TUXEDO></HYATT>");*/
        (void)sprintf(line,"<HYATT xmlns='HYATT'><TUXEDO><SERVICENAME>RtmasFncs</SERVICENAME></TUXEDO><RESERVE><i_wnd>1</i_wnd><pc_tran_typ>T</pc_tran_typ><pc_std_vars>8.4.1	163	DMD	DAVIS-HY8/M	231	OMARO	CHIR	G46158620V	3	YYYYYYYYYYYYNYYYYYYYYYNYYYYNYYYYYYYYYYYYYYNYNYYYYYYYYYYYYYYYYYYYYYYYYYNNNNNYYYYYYNNNYYNNNYNYYYYYYYYYYYYYYYYYYYYYYYYY\
</pc_std_vars><pc_in_crit>		Q		N		CHIRC	250											</pc_in_crit><pc_pln_in></pc_pln_in><pc_daycd_in></pc_daycd_in><pc_dep_rtpln_in></pc_dep_rtpln_in><pc_rates_in></pc_rates_in></RESERVE></HYATT>");
        /* send balance request and relinquish line control. */
 if ((cd = tpconnect("RtmasFncs",line,strlen(line)+2,TPSENDONLY)) == -1)
    {
        (void)fprintf(stderr,"tpconnect failed tperrno %d\n", tperrno);
        (void)userlog("tpconnect failed tperrno %d", tperrno);
        (void)tpterm();
        exit(1);
    }
//        if (tpsend(cd,line,0,TPRECVONLY,&revent) == -1)
//        {
//            (void)fprintf(stderr,"tpsend failed tperrno %d\n", tperrno);
//            (void)userlog("tpsend failed tperrno %d", tperrno);
//            (void)tpterm();
//            exit(1);
//        }
        /* wait for service to return balance request results. */
        if (tprecv(cd,&line,&len,TPNOCHANGE,&revent) != -1)
        {
            (void)fprintf(stderr,"tprecv failed tperrno %d revent %ld\n",
                          tperrno,revent);
            (void)userlog("tprecv failed tperrno %d revent %ld",
                          tperrno,revent);
            (void)tpterm();
            exit(1);
        }
        /* anything other than a send or disconnect event is an error.*/
        if ((tperrno != TPEEVENT) || ((revent != TPEV_SENDONLY) &&
                                      (revent != TPEV_SVCSUCC)))
        {
            (void)fprintf(stderr,"tprecv failed tperrno %d revent %ld\n",
                          tperrno,revent);
            (void)userlog("tprecv failed tperrno %d revent %ld",
                          tperrno,revent);
            (void)tpterm();
            exit(1);
        }
        printf("return result line =%s\n", line);
    }
    /*结束添加*/

    /* Leave application */
    if (tpterm() == -1)
    {
        (void)fprintf(stderr,"failed to leave application\n\n");
        (void)userlog("failed to leave application\n");
        exit(1);
    }
    return(0);
}

